package mo.leetcode_top;

public class L76 {

    public String minWindow(String s, String t) {
        int[] arr = new int[128];
        for (char c : t.toCharArray()) {
            arr[c-'A']++;
        }
        int left = 0;
        int cnt = 0;
        int minLeft = -1;
        int minLen = Integer.MAX_VALUE;
        for (int i = 0; i < s.length(); i++) {
            if ((--arr[s.charAt(i)-'A']) >= 0) {
                cnt++;
            }
            while (cnt == t.length()) {
                if (minLen > (i - left + 1)) {
                    minLen = i - left + 1;
                    minLeft = left;
                }
                if ((++arr[s.charAt(left)-'A']) > 0) {
                    cnt--;
                }
                left++;
            }
        }
        return minLeft == -1 ? "" : s.substring(minLeft, minLeft+minLen);
    }

    public static void main(String[] args) {
        L76 test = new L76();
        System.out.println(test.minWindow("ADOBECODEBANC", "ABC"));
    }

}
